package org.abacus.platform.util;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ValidatorUtilTest {

	@Before
	public void initData() {
	}

	public Object[][] ValidIPAddressProvider() {
		return new Object[][] { new Object[] { "1.1.1.1" }, new Object[] { "255.255.255.255" }, new Object[] { "192.168.1.1" },
				new Object[] { "10.10.1.1" }, new Object[] { "132.254.111.10" }, new Object[] { "26.10.2.10" }, new Object[] { "127.0.0.1" } };
	}

	public Object[][] InvalidIPAddressProvider() {
		return new Object[][] { new Object[] { "10.10.10" }, new Object[] { "10.10" }, new Object[] { "10" }, new Object[] { "a.a.a.a" },
				new Object[] { "10.0.0.a" }, new Object[] { "10.10.10.256" }, new Object[] { "222.222.2.999" }, new Object[] { "999.10.10.20" },
				new Object[] { "2222.22.22.22" }, new Object[] { "22.2222.22.2" }, new Object[] { "10.10.10" }, new Object[] { "10.10.10" }, };
	}

	public void ValidIPAddressTest(String ip) {
		ValidIPAddressProvider();
		boolean valid = ValidatorUtil.isIPV4(ip);
		System.out.println("IPAddress is valid : " + ip + " , " + valid);
		Assert.assertEquals(true, valid);
	}

	public void InValidIPAddressTestss(String ip) {
		InvalidIPAddressProvider();
		boolean valid = ValidatorUtil.isIPV4(ip);
		System.out.println("IPAddress is valid : " + ip + " , " + valid);
		Assert.assertEquals(false, valid);
	}

	@Test
	public void isIPV4() {
		String ip = "01.10.10.10";
		boolean valid = ValidatorUtil.isIPV4(ip);
		System.out.println("IPAddress is valid : " + ip + " , " + valid);
		Assert.assertEquals(false, valid);
	}

	@Test
	public void isEmanil() {
		String email = "179084436@qq-.com";
		boolean valid = ValidatorUtil.isEmail(email);
		System.out.println("email is valid : " + email + " , " + valid);
		Assert.assertEquals(false, valid);
	}
}
